<%--
  Created by IntelliJ IDEA.
  User: 贾振鹏
  Date: 2021/6/2
  Time: 20:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <%-- kindeditor相关 --%>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <title></title>


    <link rel="stylesheet" href="${css}/pintuer.css">
    <link rel="stylesheet" href="${css}/admin.css">
    <%-- kindeditor相关 --%>
    <link rel="stylesheet" type="text/css" href="${kindeditor}/themes/default/default.css">
    <link rel="stylesheet" type="text/css" href="${kindeditor}/plugins/code/prettify.css">

    <script src="${js}/jquery.js"></script>
    <script src="${js}/pintuer.js"></script>
    <%-- kindeditor相关 --%>
    <script type="text/javascript" src="${kindeditor}/kindeditor-all-min.js"></script>
    <script type="text/javascript" src="${kindeditor}/lang/zh-CN.js"></script>
    <script type="text/javascript" src="${kindeditor}/plugins/code/prettify.js"></script>
    <script>
        KindEditor.ready(function(K) {
            var editor1 = K.create('#editor_id', {
                cssPath : '${kindeditor}/css/prettify.css',
                uploadJson : '${root}/admin/news/editUpload',
                fileManagerJson : '${root}/admin/news/editUpload'
            });
        });

        //先上传 文件  异步方式实现上传  上传完成后  回显文件的地址信息  在  文本域显示
    </script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="${root}/admin/news/edit">
            <input type="hidden" name="id" value="${news.id}">
            <div class="form-group">
                <div class="label">
                    <label>标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="${news.title}" name="title" data-validate="required:请输入标题" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>作者：</label>
                </div>
                <div class="field">
                    <select name="author" id="author" class="input w50">
                        <option value="网站自创">网站自创</option>
                        <option value="新华网转载">新华网转载</option>
                        <option value="央视网转载">央视网转载</option>
                        <option value="人民网转载">人民网转载</option>
                        <option value="新浪网转载">新浪网转载</option>
                        <option value="搜狐网转载">搜狐网转载</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <input type="file" id="url1" name="newsImage" class="input tips" style="width:25%; float:left;"  value=""  data-toggle="hover" data-place="right" data-image="${news.image}" />
                    <input type="hidden" name="image" id="image" value="${news.image}">
                </div>
                <div class="tips"></div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label>视频：</label>
                </div>
                <div class="field">
                    <input type="file" id="url2" name="newsVideo" class="input tips" style="width:25%; float:left;"  value=""  data-toggle="hover" data-place="right" data-image="" />
                    <input type="hidden" name="videos" id="videos" value="${news.videos}">
                </div>
                <div class="tips"></video>
                </div>
            </div>

            <if condition="$iscid eq 1">
                <div class="form-group">
                    <div class="label">
                        <label>新闻类型：</label>
                    </div>
                    <div class="field">
                        <select name="category" id="category" class="input w50">
                            <option value="">请选择类型</option>
                            <c:forEach items="${categoryList}" var="category">
                                <option value="${category.category}" <c:if test="${news.category eq category.category}">checked</c:if>>${category.category}</option>
                            </c:forEach>
                        </select>
                        <div class="tips"></div>
                    </div>
                </div>
                <%--<div class="form-group">
                    <div class="label">
                        <label>其他属性：</label>
                    </div>
                    <div class="field" style="padding-top:8px;">

                        置顶 <input id="istop" name="istop" type="checkbox" value="1" <c:if test="${news.istop eq 1}">checked</c:if>/>
                    </div>
                </div>--%>
            </if>
            <input type="hidden" name="istop" value="${news.istop}">
            <div class="form-group">
                <div class="label">
                    <label>内容：</label>
                </div>
                <div class="field">
                    <textarea name="content" id="editor_id" class="input" style="height:400px; border:1px solid #ddd;">
                        ${news.content}
                    </textarea>
                    <div class="tips"></div>
                </div>
            </div>

            <div class="clear"></div>

            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit"> 修改</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    $(function () {
        //数据回显
        $("#author").find("option[value='${news.author}']").attr("selected",'selected');
        $("#category").find("option[value='${news.category}']").attr("selected",'selected');


        $("#url1").change(function () {
            var formdata = new FormData();
            formdata.append("newsImage", document.getElementById("url1").files[0]);
            var url = "${root}/admin/news/upload";
            $.ajax({
                url: url,
                type: "post",
                data: formdata,
                contentType: false,
                processData: false,
                success: function (data) {
                    $("#image").val(data.imageSrc)
                }
            })
        })

        $("#url2").change(function () {
            var formdata = new FormData();
            formdata.append("newsImage", document.getElementById("url2").files[0]);
            var url = "${root}/admin/news/upload";
            $.ajax({
                url: url,
                type: "post",
                data: formdata,
                contentType: false,
                processData: false,
                success: function (data) {
                    $("#videos").val(data.imageSrc)
                }
            })
        })
    })

</script>

</body>
</html>
